package com.dotflat.check.domain.C.PO;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Data;

import javax.xml.bind.JAXBException;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.List;

@Data
@XmlRootElement(name = "GetGuardianChildResult")  // 父节点名称
@XmlAccessorType(XmlAccessType.FIELD) //定义这个类中的何种类型需要映射到XML
public class GetGuardianChildResultPO {


    @JSONField(name = "ChildId")
    Integer ChildId = 0;

    @JSONField(name = "GuardianInfoId")
    Integer GuardianInfoId = 0;
    /**
     * 将对象转为流程XML
     *
     * @return
     * @throws JAXBException
     */
    public static String convertToXML(List<GetGuardianChildResultPO> list) {
        String data = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
                "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\n" +
                "    <soap:Body>\n" +
                "        <GetGuardianChildResponse xmlns=\"http://tempuri.org/\">\n" +
                "            <GetGuardianChildResult>${v}</GetGuardianChildResult>\n" +
                "        </GetGuardianChildResponse>\n" +
                "    </soap:Body>\n" +
                "</soap:Envelope>";
        String xmlStr = JSON.toJSONString(list);
        data = data.replace("${v}", xmlStr);
        return data;
    }

}
